/*
 *引用JQUERY类库 
 *
 * 内容页相关JS代码
 */

$(function(){

})



function submint(){
	//校验文本内容
	var comment = $('#message').val();
	comment   =   comment.Trim();
	if(comment == "please leave your comment here..." || comment =='')
	{
		alert("说点啥呗！");
		$('#message').focus();
		return false;
	}
	//校验用户名
	var username = $('#username').val();
	username   =   username.Trim();
	if(username == "Name" || username =='')
	{
		alert("请留大名！");
		$('#username').focus();
		return false;
	}
	//校验用户邮箱
	var email = $('#email').val();
	email   =   email.Trim();
	var CheckEmail = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/;
	if(!CheckEmail.test(email))
	{
		alert("请输入正确的邮箱地址！");
		$('#email').focus();
		return false;
	} 
	
	var commentid = $('#commentid').val();
	var userurl = $('#url').val(); 


	var url ="http://localhost/xmates/content/add_comment";
	$.post(url,{comment:comment,username:username,email:email,userurl:userurl,commentid:commentid},function(data){
		$('#comment_area').empty();
		var html = '';
		$.each(data,function(commentIndex,comment){
			html +='<div class="comment">'+
						'<div class="avatar">'+
							'<img src="http://localhost/xmates/images/avatar1.jpg" alt="" width="80" height="80" /><br />'+
							'<span>'+comment['username']+'</span><br />'+comment['ctime']+
						'</div>'+'<p>'+comment['content']+'</p>'+
					'</div>'
		})
		
		$('#comment_area').html(html);
	},"json")
}


function show_all(){
	var total = $('#total').attr('t');
	var commentid = $('#commentid').val();
	
	var url ="http://localhost/xmates/content/get_total_comment";
	$.post(url,{total:total,commentid:commentid},function(data){
		
		var html = '';
		$.each(data,function(commentIndex,comment){
			html +='<div class="comment">'+
						'<div class="avatar">'+
							'<img src="http://localhost/xmates/images/avatar1.jpg" alt="" width="80" height="80" /><br />'+
							'<span>'+comment['username']+'</span><br />'+comment['ctime']+
						'</div>'+'<p>'+comment['content']+'</p>'+
					'</div>'
		})
		
		$('#comment_area').append(html);
	},"json")
	
}

//文本区清除默认文字和恢复
var defaultvalue="please leave your comment here...";
function ClearDefault(element)
{
  
   if(element.value==defaultvalue)
   {
     element.value = "";
   }
}
function AddDefault(element)
{ 
 
  if(element.value=="")
  { element.value =defaultvalue; }
}
//end 文本区清除默认文字和恢复

/***********************************
 * 
 *出处:网上搜集   
 *Trim() 去除左右空格
 *Ltrim() 去除左空格
 *RTrim()  去除右空格
 *
 ************************************/    
String.prototype.Trim = function()   
{   
	return this.replace(/(^\s*)|(\s*$)/g, "");   
}   
String.prototype.LTrim = function()   
{   
	return this.replace(/(^\s*)/g, "");   
}   
String.prototype.RTrim = function()   
{   
	return this.replace(/(\s*$)/g, "");   
}   
 //end 去除空格